package net.jueb.frameworkDemo.se.observer.eventBus2.impl;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.jueb.frameworkDemo.se.observer.eventBus2.Event;
import net.jueb.frameworkDemo.se.observer.eventBus2.EventBus;
import net.jueb.frameworkDemo.se.observer.eventBus2.Receiver;

public abstract class AbstractReceiver<T> implements Receiver<T> {
	protected final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
	
	@Resource
	protected EventBus eventBus;

	@PostConstruct
	private void init() {
		String[] arg3;
		int arg2 = (arg3 = this.getEventNames()).length;

		for (int arg1 = 0; arg1 < arg2; ++arg1) {
			String name = arg3[arg1];
			this.eventBus.register(name, this);
		}

	}

	public abstract String[] getEventNames();

	public void onEvent(Event<T> event) {
		T content = event.getBody();
		doEvent(content);
	}

	/**
	 * 处理事件
	 * @param EVENT
	 */
	public abstract void doEvent(T EVENT);
}